//
//  UIScrollView+BKOrderHeader.m
//  bestkeep
//
//  Created by yons on 16/11/25.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "UIScrollView+BKOrderHeader.h"
#import <objc/runtime.h>

@implementation UIScrollView (BKOrderHeader)

char const BKOrderHeaderKey = '\0';

-(void)setBKOrder_Header:(UIView *)BKOrder_Header {
    
    objc_setAssociatedObject(self, &BKOrderHeaderKey, BKOrder_Header, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    CGRect headerFrame = BKOrder_Header.frame;
    headerFrame.origin.y = -CGRectGetHeight(headerFrame);
    BKOrder_Header.frame = headerFrame;
    
    CGFloat height = CGRectGetHeight(BKOrder_Header.frame);
    
    self.contentInset = UIEdgeInsetsMake(height, 0, 0, 0);
    
    self.contentOffset = CGPointMake(0, -height);
    
    [self addSubview:BKOrder_Header];
}

-(UIView *)BKOrder_Header {
    return objc_getAssociatedObject(self, &BKOrderHeaderKey);
}

@end
